/*
 * MyPlayer.cpp
 *
 */
 #include <QtGui>
 #include <QtNetwork>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNodeList>

 #include "HTTP_window.h"
/*
 * --------------------------------------------------------------
 * --------------------------------------------------------------
 */
 HttpWindow::HttpWindow()
 {
     listWidget = new QListWidget(this);
     
  	connect(listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));     
      
    pushBut = new QPushButton("Play", this);
    connect(pushBut, SIGNAL(pressed()),SLOT(PlayFile()));  
  	     
     QVBoxLayout *mainLayout = new QVBoxLayout;
     mainLayout->addWidget(listWidget);  
     mainLayout->addWidget(pushBut);       
     setLayout(mainLayout);

     addTestData();
 }
 /*
  * --------------------------------------------------------------
  * --------------------------------------------------------------
  */

   void HttpWindow::addTestData()
   {
       //Clear items
       listWidget->clear();
       items.clear();
       
       MyDataItem newIttem1;                
       newIttem1.audio = "http://yggdrasilradio.net:8000/";
       newIttem1.title = "yggdrasil";
       items.append(newIttem1);

       MyDataItem newIttem2;
       newIttem2.audio = "http://50.7.70.66:8795";
       newIttem2.title = "Konata Radio";
       items.append(newIttem2);
       
        
       MyDataItem newIttem3;              
       newIttem3.audio = "http://armitunes.com:8010/";
       newIttem3.title = "armitunes";
       items.append(newIttem3);      

       MyDataItem newIttem4;             
       newIttem4.audio = "http://od.netro.ca/netrostream113/voice_demo.wma";  
       newIttem4.title = "http: voice_demo.wma";
       items.append(newIttem4);      

    
       MyDataItem newIttem5;
       newIttem5.audio = "rtsp://qt2.netro.ca/princess_54.3gp";
       newIttem5.title = "rtsp: princess_54.3gp";
       items.append(newIttem5);
           
       
       for(int i=0; i< items.count(); i++){
 		  listWidget->addItem(items[i].title);
       }  
   }

/*
* --------------------------------------------------------------
* --------------------------------------------------------------
*/
void HttpWindow::PlayFile()
{
    int selIndex = listWidget->currentRow();
    
    if(selIndex >= 0 && selIndex < items.count()){
        emit streamSelected(items[selIndex].audio);
    }    
}
 /*
  * --------------------------------------------------------------
  * --------------------------------------------------------------
  */
 void HttpWindow::itemSelected(QListWidgetItem *item)
 {
     PlayFile();
 }

